import 'package:flutter/material.dart';
import 'package:x3_component_core/utils/base_component_utils.dart';
import 'package:x3_component_core/components/layout_components/base_card_component.dart';

class BaseTitleCardComponent extends StatelessWidget {

  /// 标题
  final String title;

  /// 组件
  final Widget child;

  /// 标题按钮的点击事件
  final Function onPress;

  BaseTitleCardComponent({Key key, @required this.title, @required this.child, this.onPress}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BaseCardComponent(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container( padding: EdgeInsets.only(bottom: 12.0), child: this._buildCardContent( context, name: this.title, onPress: onPress ) ),
          child,
        ],
      ),
    );
  }

  Widget _buildCardContent( BuildContext context, { String name, Function onPress } ) {
    return InkWell(
      onTap: onPress,
      child: Padding(
        padding: const EdgeInsets.symmetric(vertical: 4.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(name, style: Theme.of(context).textTheme.bodyText2.copyWith(fontSize: 14, fontWeight: FontWeight.bold)),
            onPress != null ? BaseComponentUtils.buildListViewRightIcon(context) : SizedBox(),
          ],
        ),
      ),
    );
  }

}
